/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
 // 递归法
func minDepth(root *TreeNode) int {
    if root == nil {
        return 0
    }
    if root.Right == nil && root.Left != nil{
        return 1+minDepth(root.Left)
    }
    if root.Left == nil && root.Right != nil {
        return 1+minDepth(root.Right)
    }
    return min(minDepth(root.Left), minDepth(root.Right)) + 1
}

func min(a, b int) int {
    if a > b {
        return b
    }
    return a
}